package activities;

import helper.ExpandableListAdapter;
import helper.ExpandableListParent;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ExpandableListView;

import com.example.intellifit.R;

public class WorkoutPlanActivity extends Activity {
	private ExpandableListView mExpandableList;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_workout_plan);
	 
        mExpandableList = (ExpandableListView)findViewById(R.id.expandable_list);
 
        //create a default workout plan
        ArrayList<ExpandableListParent> arrayParents = createDefaultWorkoutPlan();
        //sets the adapter that provides data to the list.
        mExpandableList.setAdapter(new ExpandableListAdapter(WorkoutPlanActivity.this, arrayParents));
 	}
 	
	/**
	 * Creates a default workout plan consisting of 4 weeks and the corresponding number of training days
	 * @return
	 */
 	private ArrayList<ExpandableListParent> createDefaultWorkoutPlan(){
 		ArrayList<ExpandableListParent> arrayParents = new ArrayList<ExpandableListParent>();
        ArrayList<String> arrayChildren = new ArrayList<String>();
 
        //create 4 parent items representing the training weeks
        for (int i = 0; i < 4; i++){
            
            ExpandableListParent parent = new ExpandableListParent();
            parent.setTitle("Training Week " + (i+1));
            
             
            arrayChildren = new ArrayList<String>();
            for (int j = 0; j < 7; j++) {
                arrayChildren.add("Day " + (j+1));
                
            }
            parent.setArrayChildren(arrayChildren);
 
            //in this array we add the Parent object. We will use the arrayParents at the setAdapter
            arrayParents.add(parent);
        }
        return arrayParents;
 	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.workout_plan, menu);
		return true;
	}

}
